#ifndef basicparser_h__
#define basicparser_h__

#include <set>
#include "tokenizer.h"
#include "syntaxtree.h"
#include "utills.h"

namespace CCompiler
{
    const int lowest_level = 10;

    extern std::set<TokenType> OpGroups[lowest_level + 1];
    extern std::set<TokenType> UnaryOps;
    extern std::set<TokenType> AssignOps;
    extern std::map<std::string, std::string> AssignOp2BinOp;

    class BasicParser
    {
    protected:
        Tokenizer &tokenizer_;
        Token tok_;
        TokenType getTokenType() { return tok_.getTokenType(); }
        Token nextToken() { return tok_ = tokenizer_.nextToken(); }
        template<int priority>
        SynExpression *internalParseExpression(Int2Type<priority>);
        virtual SynExpression *internalParseExpression(Int2Type<lowest_level>);
        virtual SynExpression *parseIdentifier();
    public:
        BasicParser(Tokenizer &tokenizer): tokenizer_(tokenizer), tok_(tokenizer_.getCurToken()) {}
        SynExpression *parseExpression();
    };
}

namespace __InitializeBasicParser { void initialize(); }



#endif // basicparser_h__
